home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue35 / pageprnt / PAGEPRNT.ZIP / PagePrnt / PgPrnReg.pas < prev    next >
Pascal/Delphi Source File  |  1997-09-25  |  5KB  |  171 lines

  1. unit PgPrnReg;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, DsgnIntf, TypInfo, PagePrnt;
  8.  
  9. type
  10.   TFriendlyFmtDlg = class(TForm)
  11.     Edit: TEdit;
  12.     List: TListBox;
  13.     btnOK: TButton;
  14.     btnCancel: TButton;
  15.     procedure ListDblClick(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22.   TFriendlyFormatProperty = class(TStringProperty)
  23.   public
  24.     procedure Edit; override;
  25.     function GetAttributes: TPropertyAttributes; override;
  26.   end;
  27.  
  28.   TPagePrinterComponentEditor = class(TDefaultEditor)
  29.   public
  30.     //Makes a double-click go to the OnNewPage event.
  31.     procedure EditProperty(PropertyEditor: TPropertyEditor;
  32.               var Continue, FreeEditor: Boolean); override;
  33.     //Sets up the design-time verbs.
  34.     procedure ExecuteVerb(Index: Integer); override;
  35.     function GetVerb(Index: Integer): string; override;
  36.     function GetVerbCount: Integer; override;
  37.   end;
  38.  
  39. procedure Register;
  40.  
  41. implementation
  42.  
  43. {$R *.DFM}
  44.  
  45. uses
  46.     PgPrnAbt;
  47.  
  48. {============ TFriendlyFmtDlg ============}
  49.  
  50. procedure TFriendlyFmtDlg.ListDblClick(Sender: TObject);
  51. var
  52.    S: String;
  53. begin
  54.      S:=Copy(List.Items[List.ItemIndex], 1, 2);
  55.      if S <> '--' then Edit.SelText:=S;
  56.      if Edit.CanFocus then Edit.SetFocus;
  57. end;
  58.  
  59. {============ TFriendlyFormatProperty ============}
  60.  
  61. procedure TFriendlyFormatProperty.Edit;
  62. var
  63.   FriendlyFmtDlg: TFriendlyFmtDlg;
  64. begin
  65.      FriendlyFmtDlg := TFriendlyFmtDlg.Create(Application); { construct the editor }
  66.      try
  67.         FriendlyFmtDlg.Edit.Text := GetStrValue;      { use the existing value }
  68.         if FriendlyFmtDlg.ShowModal = mrOk then       { if the user OKs the dialog... }
  69.            SetStrValue(FriendlyFmtDlg.Edit.Text);     { ...use the result to set value }
  70.      finally
  71.             FriendlyFmtDlg.Free; { destroy the editor }
  72.      end;
  73. end;
  74.  
  75. function TFriendlyFormatProperty.GetAttributes: TPropertyAttributes;
  76. begin
  77.      Result:=(inherited GetAttributes)+[paDialog];
  78. end;
  79.  
  80. {============ TPagePrinterComponentEditor ============}
  81.  
  82. procedure TPagePrinterComponentEditor.EditProperty(PropertyEditor: TPropertyEditor;
  83.           var Continue, FreeEditor: Boolean);
  84. begin
  85.      if (PropertyEditor is TMethodProperty) and
  86.         (CompareText(PropertyEditor.GetName, 'OnNewPage') = 0) then
  87.      begin
  88.           inherited EditProperty(PropertyEditor, Continue, FreeEditor);
  89.      end;
  90. end;
  91.  
  92. procedure TPagePrinterComponentEditor.ExecuteVerb(Index: Integer);
  93. var
  94.    AboutBox: TPgPrnAboutBox;
  95. begin
  96.      case Index of
  97.           0: begin //Preview
  98.                   with Component as TPagePrinter do
  99.                   begin
  100.                        BeginDoc;
  101.                        WriteLines(False);
  102.                        EndDoc;
  103.                   end;
  104.                   Designer.Modified;
  105.              end;
  106.           1: begin //About...
  107.                   AboutBox:=TPgPrnAboutBox.Create(Application);
  108.                   try
  109.                      AboutBox.ShowModal;
  110.                   finally
  111.                          AboutBox.Free;
  112.                   end;
  113.              end;
  114.           2: begin //Next Page
  115.                   with Component as TPagePrinter do
  116.                   begin
  117.                        if (PageCount > 0) and (PageNumber < PageCount) then
  118.                           PageNumber:=PageNumber+1;
  119.                   end;
  120.                   Designer.Modified;
  121.              end;
  122.           3: begin //Prev Page
  123.                   with Component as TPagePrinter do
  124.                   begin
  125.                        if (PageCount > 0) and (PageNumber > 1) then
  126.                           PageNumber:=PageNumber-1;
  127.                   end;
  128.                   Designer.Modified;
  129.              end;
  130.           4: begin //Clear
  131.                   with Component as TPagePrinter do
  132.                        Clear;
  133.                   Designer.Modified;
  134.              end;
  135.      end;
  136. end;
  137.  
  138. function TPagePrinterComponentEditor.GetVerb(Index: Integer): string;
  139. begin
  140.      case Index of
  141.           0: Result:='Preview';
  142.           1: Result:='About TPagePrinter...';
  143.           2: Result:='Next Page';
  144.           3: Result:='Previous Page';
  145.           4: Result:='Clear';
  146.      end;
  147. end;
  148.  
  149. function TPagePrinterComponentEditor.GetVerbCount: Integer;
  150. begin
  151.      Result:=2;
  152.      with Component as TPagePrinter do
  153.           if PageCount > 0 then Result:=5
  154. end;
  155.  
  156. {=============================================================================}
  157. { Register Function for TPagePrinter.                                         }
  158. {=============================================================================}
  159.  
  160. procedure Register;
  161. begin
  162.      RegisterComponents('Menees', [TPagePrinter]);
  163.      RegisterPropertyEditor(TypeInfo(String), TPagePrinter,
  164.          'FriendlyHeader', TFriendlyFormatProperty);
  165.      RegisterPropertyEditor(TypeInfo(String), TPagePrinter,
  166.          'FriendlyFooter', TFriendlyFormatProperty);
  167.      RegisterComponentEditor(TPagePrinter, TPagePrinterComponentEditor);
  168. end;
  169.  
  170. end.
  171.